package com.sunday.aomicaichang.adpter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunday.aomicaichang.R;
import com.sunday.aomicaichang.model.Integral;

import java.math.BigDecimal;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/6/4.
 */

public class IntegralAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private Context mContext;
    private List<Integral.RecordsBean> recordsBeanList;

    public IntegralAdapter(Context mContext) {
        this.mContext = mContext;

    }

    public void setmData(List<Integral.RecordsBean> recordsBeanList) {
        this.recordsBeanList = recordsBeanList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_my_integral, parent, false);
        return new ItemViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        Integral.RecordsBean recordsBean = recordsBeanList.get(position);
        ItemViewHolder viewHolder = (ItemViewHolder) holder;

        if (recordsBean.getCreateDate() != null)
            viewHolder.time.setText(recordsBean.getCreateDate());
        viewHolder.mode.setText(recordsBean.getRemark());
        viewHolder.num.setText(recordsBean.getScore() + "");
        if(recordsBean.getScore().compareTo(new BigDecimal("0.00"))<0){
            viewHolder.num.setTextColor(ContextCompat.getColor(mContext,R.color._ed6d00));
        }else {
            viewHolder.num.setTextColor(ContextCompat.getColor(mContext,R.color._666));
        }
    }

    @Override
    public int getItemCount() {
        return recordsBeanList == null ? 0 : recordsBeanList.size();
    }


    public class ItemViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.time)
        TextView time;
        @Bind(R.id.mode)
        TextView mode;
        @Bind(R.id.num)
        TextView num;

        public ItemViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
